// 1810.[字符串分割模拟]日志敏感信息屏蔽
// https://oj.rnd.huawei.com/problems/1810/details
// 敏感信息屏蔽规则：1、key为password或pwd的：对应的 value 统一用6个*替代。
// 2、key在words中，且以IP（不区分大小写）结尾的：对应value中ip地址中间两段分别用3个*
// 替代 不用考虑IPv6格式，用例保证IP格式的合法性。
// 3、key在words中，且以非IP结尾的：仅需对value中最右侧的长度L大于等于4，且连续为数字的子串进行屏蔽，
// 从倒数第L/4+1个数字字符开始，比如L为9从倒数第3个开始，从右到左对中间的L/2个字符用*替代。
// 非敏感信息处理规则：原样输出。
// 输入 5
// IMSI CellID UserIP CID UID
// Apn:cmnet,Qos:121212121212,CellID:4600175319,Imsi:460019852146201,GWIP:1.1.1.1,UserIp:2.2.2.2,CID:854710-336985-852,UID:1-2-3-4,pwd:huawei7410
// 输出
// Apn:cmnet,Qos:121212121212,CellID:460*****19,Imsi:46001*******201,GWIP:1.1.1.1,UserIp:2.***.***.2,CID:854710-33***5-852,UID:1-2-3-4,pwd:******
// cur,  last
//  1     1     => app
//  1     0     => new
//  0     1     => new
//  0     0     => app

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

vector<string> string_split(const string& str, char delim) {
  istringstream iss(str);
  vector<string> result;
  string token;
  while (getline(iss, token, delim)) {
    result.push_back(token);
  }
  return result;
}

//  D  ,  LastD
//  1     1     => app
//  1     0     => new
//  0     1     => new
//  0     0     => app
string string_split_number(const string& strLine) {
  vector<string> vtStr;
  string str1;
  bool isLastDigit = false;
  for (auto c : strLine) {
    bool curIsDigit = isdigit(c);
    if ((curIsDigit && isLastDigit) || (!curIsDigit && !isLastDigit)) {
      str1 += c;
    } else {
      vtStr.push_back(str1);
      str1 = c;
    }
    isLastDigit = curIsDigit;
  }
  if (!str1.empty()) {
    vtStr.push_back(str1);
  }
  for (int i = vtStr.size() - 1; i >= 0; i--) {
    string& str = vtStr[i];
    if (str.length() >= 4 && isdigit(str[0])) {
      int end = str.length() / 4 + 1 - 1;
      int len = str.length() / 2;
      //        =     6       -  2   - 3
      int start = str.length() - end - len;
      // printf("%s,start=%d,%d,%d.", str.c_str(),start,end,len);
      str.replace(start, len, string(len, '*'));
      break;
    }
  }
  string res;
  for (auto str : vtStr) {
    res += str;
  }
  return res;
}

// 待实现函数，在此函数中填入答题代码
vector<pair<string, string>> InterfereLogs(
    const vector<string>& keys, const vector<pair<string, string>>& logs) {
  vector<pair<string, string>> newLogs;
  for (auto word : logs) {
    string sKey = word.first;
    string sVal = word.second;
    std::transform(sKey.begin(), sKey.end(), sKey.begin(), ::tolower);

    bool bFoundKey = false;
    auto iter = std::find_if(keys.begin(), keys.end(), [sKey](string str) {
      std::transform(str.begin(), str.end(), str.begin(), ::tolower);
      return sKey == str;
    });
    if (iter != std::end(keys)) {
      bFoundKey = true;
    }
    if (sKey == "password" || sKey == "pwd") {
      sVal = "******";
    } else if (bFoundKey && sKey.substr(sKey.length() - 2, 2) == "ip") {
      vector<string> vtTmp = string_split(sVal, '.');
      sVal = vtTmp[0];
      sVal += ".***.***.";
      sVal += vtTmp[3];
    } else if (bFoundKey) {
      // dealwith number
      sVal = string_split_number(sVal);
    }
    newLogs.push_back(make_pair(word.first, sVal));
  }
  return newLogs;
}

// 以下为考题输入输出框架，此部分代码不建议改动
inline int ReadInt() {
  int number;
  std::cin >> number;
  return number;
}

template <typename T>
inline std::vector<T> ReadVector(int size) {
  std::vector<T> objects(size);
  for (int i = 0; i < size; ++i) {
    std::cin >> objects[i];
  }
  return objects;
}

inline std::string ReadLine() {
  std::string line;
  std::getline(std::cin, line);
  return line;
}

std::vector<std::string> ReadWords(char delimeter) {
  std::string line = ReadLine();
  std::istringstream iss(line);
  std::vector<std::string> words;
  while (!iss.eof()) {
    std::string word;
    std::getline(iss, word, delimeter);
    if (!word.empty()) {
      words.push_back(word);
    }
  }
  return words;
}

inline std::pair<std::string, std::string> SplitPair(const std::string& word,
                                                     char delimeter) {
  auto pos = word.find(delimeter);
  return make_pair(word.substr(0, pos), word.substr(pos + 1));
}

int main() {
  int count = ReadInt();
  ReadLine();
  auto keys = ReadVector<string>(count);
  ReadLine();
  auto rawLogs = ReadWords(',');
  vector<pair<string, string>> logs(rawLogs.size());
  transform(rawLogs.begin(), rawLogs.end(), logs.begin(),
            [](string word) { return SplitPair(word, ':'); });
  auto result = InterfereLogs(keys, logs);
  auto it = result.begin();
  if (it == result.end()) {
    return 0;
  }
  std::cout << it->first << ':' << it->second;
  for (++it; it != result.end(); ++it) {
    std::cout << ',' << it->first << ':' << it->second;
  }
  std::cout << std::endl;

  return 0;
}